package com.ml.rabbitmq.consumer.topic;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Service;

// 注解式绑定，有了此注解，就不需要再编写配置类
// bindings其实就是用来确定队列和交换机绑定关系
@RabbitListener(bindings = @QueueBinding(
        value = @Queue(value = "email.topic.queue", durable = "true", autoDelete = "false"),
        exchange = @Exchange(value = "topic_order_exchange",//必须和生产者保持一致
                type = ExchangeTypes.TOPIC),// 这里是确定的rabbitmq模式是：fanout 是以广播模式 、 发布订阅模式
        key = "*.email.#"
))
@Service
public class EmailTopicService {
    // @RabbitHandler 代表此方法是一个消息接收的方法。该不要有返回值
    @RabbitHandler
    public void messageReceiver(String message){
        // 此处省略发邮件的逻辑
        System.out.println("email-------------->" + message);
    }
}
